//
//  PMSideStatisticsSearchViewController.m
//  ERP
//
//  Created by QA on 16/1/6.
//  Copyright © 2016年 ShangHai HaoLei Software Technology Co., Ltd. All rights reserved.
//

#import "PMSideStatisticsSearchViewController.h"

#import "GEInputTableViewCell.h"
#import "MTCSelectClienterViewController.h"
#import "MTCConcreteConfirmationViewController.h"

#import "NSDictionary+DataFormat.h"
#import "NSMutableDictionary+Format.h"
#import "GEPickerTextField.h"
#import "NSMutableArray+Format.h"
#import "GEWeekTimeFromatter.h"

@interface PMSideStatisticsSearchViewController ()

@property (nonatomic, strong) NSMutableDictionary *orderInfo;

@end

@implementation PMSideStatisticsSearchViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [self setTitle: @"砼方量统计筛选"];
        UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStyleDone target:self
                                                                      action:@selector(submitContractSelector:)];
        self.navigationItem.rightBarButtonItem = leftButton;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 10)];
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 10)];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)submitContractSelector:(id)selector
{
    UITextField *textField01 = [self.tableView getCellSaveClass:[UITextField class] pathForRow:0 inSection:0];
    UITextField *textField02 = [self.tableView getCellSaveClass:[UITextField class] pathForRow:1 inSection:0];
    
    //关闭页面，返回数据
    if (self.backResultDelagate && [self.backResultDelagate respondsToSelector:@selector(backResultDataKey:dataValue:)]) {
        NSArray *array = @[textField01.text, textField02.text];
        [self.backResultDelagate backResultDataKey:self.key dataValue:array];
    }
}

#pragma mark - UIAlertView

- (void)showAlertView:(NSString*)message
{
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"温馨提示" message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
    alert.alertViewStyle=UIAlertViewStyleDefault;
    [alert show];
}


#pragma mark
#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = [NSString stringWithFormat:@"CreateContractViewController%ld%ld",indexPath.section,indexPath.row];
    
    //合同基本信息
    if(indexPath.section == 0){
        GEInputTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell != nil) return cell;
        
        if(indexPath.row == 0){
            cell = [[GEInputTableViewCell alloc] initWithDateReuseIdentifier:CellIdentifier];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.titleName = @"开始日期";
            cell.placeholder = @"请选择开始日期";
            cell.isMark = YES;
            [cell setEnablePrevious:NO next:NO];
            [cell setDatePickerMode:UIDatePickerModeDate];
            [self.tableView setCellView:cell inRow:indexPath.row inSection:indexPath.section];
            
        } else if(indexPath.row == 1){
            cell = [[GEInputTableViewCell alloc] initWithDateReuseIdentifier:CellIdentifier];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.titleName = @"截止日期";
            cell.placeholder = @"请选择截止日期";
            cell.isMark = YES;
            [cell setEnablePrevious:NO next:NO];
            [cell setDatePickerMode:UIDatePickerModeDate];
            [self.tableView setCellView:cell inRow:indexPath.row inSection:indexPath.section];
        }
        return cell;
    }
    
    return nil;
}

#pragma mark
#pragma mark - UITableViewDelegate

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    //键盘事件处理
    UITextField *textField = [self.tableView getCellSaveClass:[UITextField class] pathForRow:indexPath.row inSection:indexPath.section];
    if (textField) [textField becomeFirstResponder];
}

#pragma mark
#pragma mark - Button Event

- (void)backButtonEvent:(id)sender
{
    //关闭页面，返回数据
    if (self.backResultDelagate && [self.backResultDelagate respondsToSelector:@selector(backResultDataKey:dataValue:)]) {
        [self.backResultDelagate backResultDataKey:self.key dataValue:nil];
    }
}

@end
